//
//  AppDelegate.m
//  01-UIVIewHomeWork
//
//  Created by dllo on 16/7/14.
//  Copyright © 2016年 danming. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()<UITextFieldDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#pragma mark - 创建主window对象
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [_window makeKeyAndVisible];
    UIViewController *vc = [[UIViewController alloc] init];
    _window.rootViewController = vc;
#pragma mark - 创建背景ImageView
    // 创建UIImageVeiw对象, 作为背景图片.
    UIImageView *backImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"welcome_2"]];
    backImage.frame = _window.frame;
    [_window addSubview:backImage];
#pragma mark - 创建背景图片上的logo
    UIImageView *logoImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_lagou"]];
    logoImage.frame = CGRectMake(161, 140, 92*1.2, 148*1.2);
    [backImage addSubview:logoImage];
#pragma mark - 创建textField(用户和密码)
    UITextField *accountTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 350, 354, 40)];
    UITextField *passWordTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 391, 354, 40)];
    // 签订代理人
    accountTextField.delegate = self;
    passWordTextField.delegate = self;
    accountTextField.backgroundColor = [UIColor blackColor];
    accountTextField.alpha = 0.4;
    accountTextField.borderStyle = UITextBorderStyleRoundedRect;
    passWordTextField.borderStyle = UITextBorderStyleRoundedRect;
    passWordTextField.backgroundColor = [UIColor blackColor];
       passWordTextField.alpha = 0.4;
    accountTextField.textColor = [UIColor whiteColor];
    passWordTextField.textColor = [UIColor whiteColor];
    // 将两个textField添加到背景图片上
    [_window addSubview:accountTextField];
    [_window addSubview:passWordTextField];
#pragma mark - 创建textField前的图片
    UIImageView *accountImage = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"icon_username"]];
    UIImageView *passWordImage = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"icon_password"]];
    accountImage.frame = CGRectMake(13, 350, 40, 40);
    passWordImage.frame = CGRectMake(13, 391, 40, 40);
    accountImage.backgroundColor = [UIColor blackColor];
    passWordImage.backgroundColor = [UIColor blackColor];
    [backImage addSubview:accountImage];
    [backImage addSubview:passWordImage];
    // 给UIImageView加圆角
    accountImage.layer.cornerRadius = 5;
    passWordImage.layer.cornerRadius = 5;
#pragma mark - 创建button
    UIButton *forgetButton = [UIButton buttonWithType:UIButtonTypeSystem];
    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeSystem];
    UIButton *strollButton = [UIButton buttonWithType:UIButtonTypeSystem];
    UIButton *nowRegiserbutton = [UIButton buttonWithType:UIButtonTypeSystem];
    // 给button附上文字
    [forgetButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    [registerButton setTitle:@"登录" forState:UIControlStateNormal];
    [strollButton setTitle:@"随便逛逛>" forState:UIControlStateNormal];
    [nowRegiserbutton setTitle:@"现在注册拉勾" forState:UIControlStateNormal];
    // 设置button的frame
    registerButton.frame = CGRectMake(10, 450, 394, 40);
    forgetButton.frame = CGRectMake(10, 510, 100, 40);
    nowRegiserbutton.frame = CGRectMake(132, 570, 150, 40);
    strollButton.frame = CGRectMake(157, 650, 100, 40);
    // 设置button的背景颜色以及文字样式和颜色
    registerButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    registerButton.tintColor = [UIColor lightGrayColor];
    forgetButton.tintColor = [UIColor lightGrayColor];
    strollButton.tintColor = [UIColor lightGrayColor];
    nowRegiserbutton.tintColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    // button的字体加粗
    forgetButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    nowRegiserbutton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    strollButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    registerButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    // 设置button的圆角
    registerButton.layer.cornerRadius = 5;
    //添加到主window上
    [_window addSubview:forgetButton];
    [_window addSubview:registerButton];
    [_window addSubview:strollButton];
    [_window addSubview:nowRegiserbutton];
#pragma mark - 创建label
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(196, 610, 20, 20)];
    label.text = @"or";
    label.font = [UIFont systemFontOfSize:20];
    label.textColor = [UIColor whiteColor];
    [backImage addSubview:label];
    // 创建高度为一的UIView
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(10, 620, 160, 1.5)];
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(235, 620, 160, 1.5)];
    leftView.backgroundColor = [UIColor whiteColor];
    rightView.backgroundColor = [UIColor whiteColor];
    [backImage addSubview:leftView];
    [backImage addSubview:rightView];
    
    return YES;
}
//隐藏键盘(协议方法)
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
